package com.uenpay.im.ui.old.activity.search;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.uenpay.im.IMApplication;
import com.uenpay.im.R;
import com.uenpay.im.ui.old.activity.area.AreaActivity;
import com.uenpay.im.ui.old.activity.personal.UpdateSexActivity;
import com.uenpay.util.app.base.BaseActivity;


/**
 * @author SL
 * @created 2016-2-2 下午4:21:33
 * @copyRight http://www.qiyunxin.com
 * @function TODO
 */
public class SearchPeopleActivity extends BaseActivity {

    private TextView sex_tv, area_tv;
    private int sex = 2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        isFullScreen = true;
        super.onCreate(savedInstanceState);
    }

    @Override
    public View bindView() {
        return null;
    }

    @Override
    public int bindLayout() {
        return R.layout.activity_search_people_layout;
    }

    @Override
    public void initView(View view) {
        initView();
        initListener();
    }

    protected void initView() {
        ((TextView) findViewById(R.id.title_textview))
                .setText(R.string.search_people);
        sex_tv = (TextView) findViewById(R.id.sex_tv);
        area_tv = (TextView) findViewById(R.id.area_tv);
    }

    protected void initListener() {
        findViewById(R.id.choose_area_layout).setOnClickListener(
                new OnClickListener() {

                    @Override
                    public void onClick(View arg0) {
                        Intent intent = new Intent(SearchPeopleActivity.this, AreaActivity.class);
                        startActivityForResult(intent, 102);
                    }
                });

        findViewById(R.id.choose_sex_layout).setOnClickListener(
                new OnClickListener() {

                    @Override
                    public void onClick(View arg0) {
                        Intent intent = new Intent(SearchPeopleActivity.this,
                                UpdateSexActivity.class);
                        intent.putExtra("sex_type", sex);
                        intent.putExtra("isUpdatePersonalInfo", false);
                        startActivityForResult(intent, 100);
                    }
                });
        findViewById(R.id.search_btn).setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                Intent intent = new Intent(SearchPeopleActivity.this,
                        SearchResultListActivity.class);
                intent.putExtra("sex", sex);
                intent.putExtra("area", area_tv.getText().toString());
                startActivity(intent);
            }
        });
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == -1 && data != null) {
            if (requestCode == 100) {
                sex = data.getIntExtra("sex", 2);
                if (sex == 1) {
                    sex_tv.setText(R.string.man);
                } else if (sex == 0) {
                    sex_tv.setText(R.string.woman);
                } else {
                    sex_tv.setText(R.string.all);
                }
            } else if (requestCode == 102) {
                area_tv.setText(data.getStringExtra("result"));
            }

        }
        super.onActivityResult(requestCode, resultCode, data);
    }
}
